package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.ProductSpecService;
import com.atguigu.spzx.model.entity.system.ProductSpec;
import com.atguigu.spzx.model.vo.common.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/product/productSpec")
@Tag(name = "商品规格管理")
public class ProductSpecController {
    @Autowired
    private ProductSpecService productSpecService;

    @GetMapping("/{page},{limit}")
    @Operation(summary = "列表查询")
    public Result<PageInfo<ProductSpec>> findByPage (@PathVariable Integer page , @PathVariable Integer limit){
        PageInfo<ProductSpec> pageInfo = productSpecService.findByPage(page,limit);
        return Result.OK(pageInfo);
    }
    @PostMapping("/save")
    @Operation(summary = "添加规格")
    public Result save(@RequestBody ProductSpec productSpec){
        productSpecService.save(productSpec);
        return Result.OK();
    }
    @DeleteMapping("deleted")
    @Operation(summary = "删除规格")
    public Result deletedById (Long id){
        productSpecService.delById(id);
        return Result.OK();
    }
    @PutMapping("/update")
    @Operation(summary = "修改规格")
    public Result updateById(@RequestBody ProductSpec productSpec ){
        productSpecService.updateById(productSpec);
        return Result.OK();
    }
}
